import cv2
import os

# 输入图片文件夹路径
image_folder = '../result'

# 获取图片文件夹中的所有图片文件
images = [img for img in os.listdir(image_folder) if img.endswith(".png") or img.endswith(".jpg")]

# 获取第一张图片的宽度和高度，用于创建视频
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape

# 指定输出视频的名称和编解码器
video_name = 'output.mp4'
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(video_name, fourcc, 30, (width, height))

# 逐一将图片添加到视频中
for i in range(len(images)*2):
    image='{}.png'.format(i)
    video.write(cv2.imread(os.path.join(image_folder, image)))
for j in range(90):
    image = '{}.png'.format(len(images)*2-2)
    video.write(cv2.imread(os.path.join(image_folder, image)))
# 关闭视频文件
video.release()
